<template>
  <div class="wrap">
    <div class="sel">
      <span class="txt">关键词</span>
      <input type="text" placeholder="用户名/手机号" v-model="params.keyWord">
      <div class="btn" @click="getUserList()">搜索</div>
    </div>
    <el-table stripe style="width:100%" :data="userList">
      <el-table-column type="index" label="编号" width="50" align="center"></el-table-column>
<el-table-column prop="nickName" label="用户名称"  align="center"></el-table-column>
<el-table-column prop="userPhone" label="手机号"  align="center"></el-table-column>
<el-table-column  label="注册时间" align="center">
  <template slot-scope="scope">
    {{setDate(scope.row.registerTime)}} {{setTime(scope.row.registerTime)}}
  </template>
</el-table-column>
    </el-table>
    <el-pagination
      @current-change="handleCurrentChange"
      background
      :current-page="params.page"
      :page-size="params.limit"
      :total="params.total"
      style="text-align:center;margin:20px auto;"
      layout="prev, pager, next"
    ></el-pagination>
  </div>
</template>
<script>
import axios from "axios";
import qs from "qs";
export default {
  data() {
    return {
      loading: false,
      params: {
        limit: 10,
        page: 1,
        serviceId: this.$store.state.userId,
        keyWord: "",
        total: 0
      },
      userList: []
    };
  },
  methods: {
    /**
     * 分页
     */
    handleCurrentChange: function(index) {
      let that = this;
      that.params.page = index;
      that.getUserList();
    },
    /**
     * 获取用户列表
     */
    getUserList: function() {
      let that = this;
      this.loading = true;
      this.axios({
        method: "post",
        url: `/user/selectByKyWord`,
        data: qs.stringify(that.params)
      }).then(res => {
        this.loading = false;
        if (res.data.code == 0) {
          that.userList = res.data.data;
          that.params.total = res.data.data.length
        } else {
          this.$alert(res.data.msg); 
        }
      });
    },
    /**
     * 根据时间毫秒数 返回年月日
     */
    setDate: function(str) {
      let times = new Date(str);
      return `${times.getFullYear()}-${
        times.getMonth()+1 < 10 ? "0" + (times.getMonth()+1) : times.getMonth()+1
      }-${times.getDate() < 10 ? "0" + times.getDate() : times.getDate()}`;
    },
    /**
     * 根据时间毫秒数 返回时分秒
     */
    setTime: function(str) {
      let times = new Date(str);
      return `${
        times.getHours() < 10 ? "0" + times.getHours() : times.getHours()
      }:${
        times.getMinutes() < 10 ? "0" + times.getMinutes() : times.getMinutes()
      }:${
        times.getSeconds() < 10 ? "0" + times.getSeconds() : times.getSeconds()
      }`;
    }
  },
  mounted() {
    this.getUserList();
  }
};
</script>
<style scoped>

.wrap {
  /* padding: 68px 136px; */
  width: 90%;
  margin: 40px auto;
}
.sel {
  height: 32px;
  line-height: 32px;
  padding: 23px 20px;
  background: #fff;
}
.sel .txt {
  font-family: PingFangSC-Medium;
  font-size: 14px;
  color: rgba(37, 38, 49, 1);
  font-weight: bold;
  width: 42px;
}
.sel input {
  width: 232px;
  height: 32px;
  background: rgba(255, 255, 255, 1);
  border-radius: 16px;
  border: 1px solid rgba(232, 236, 239, 1);
  color: #888888;
  margin-left: 17px;
  text-align: center;
  box-sizing: border-box;
  outline: none;
}
.btn {
  color: #fff;
  width: 80px;
  height: 32px;
  background: #4B74FF;
  border-radius: 24px;
  border: 1px solid #4B74FF;
  text-align: center;
  margin-left: 37px;
  display: inline-block;
}
.table {
  /* width: 1490px; */
  margin-top: 43px;
  margin-left: 38px;
}
.table .sthead {
  /* width: 1490px; */
  border-bottom: 1px solid #dddddd;
  height: 67px;
  font-family: PingFangSC-Medium;
  font-size: 20px;
  color: #000000;
  line-height: 67px;
  font-weight: bold;
  background: #e0eefe;
}
.sthead {
  /* width: 1490px; */
  border: 1px solid #ddd;
  border-width: 1px 0px 1px 1px;
  height: 67px;
  background: #e0eefe;
  line-height: 67xp;
  display: flex;
  font-size: 20px;
  font-weight: bold;
  text-align: center;
}
.sthead > div {
  flex: 1;
  height: 67px;
  border-right: 1px solid #ddd;
  text-align: center;
}
.tlist {
  /* width: 1490px; */
  height: 80px;
  display: flex;
  line-height: 80px;
  border-bottom: 1px solid #ddd;
  border-left: 1px solid #ddd;
}
.tlist > div {
  flex: 1;
  height: 80px;
  border-right: 1px solid #ddd;
  text-align: center;
}
</style>
